package com.bq.server.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.bq.server.base.BaseService;
import com.bq.server.core.mapper.CadreRelationsInfoMapper;
import com.bq.server.core.model.CadreRelationsInfo;
import com.bq.server.core.vo.request.CadreRelationsInfoRequest;
import com.bq.server.service.CadreRelationsInfoService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author shchen
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class CadreRelationsInfoServiceImpl extends BaseService<CadreRelationsInfoMapper, CadreRelationsInfo> implements CadreRelationsInfoService {


    @Override
    public void saveRelations(List<CadreRelationsInfoRequest> relations, Long id) {
        if (CollUtil.isNotEmpty(relations)) {
            List<CadreRelationsInfo> collect = relations.stream().map(request -> {
                CadreRelationsInfo cadreRelationsInfo = new CadreRelationsInfo();
                BeanUtil.copyProperties(request, cadreRelationsInfo);
                cadreRelationsInfo.setCadreAppointId(id);
                return cadreRelationsInfo;
            }).collect(Collectors.toList());
            this.saveBatch(collect);
        }
    }
}





